/**
 * 详情对话框
 */
var SysDistrictInfoDlg = {
    data: {
        parentId: "",
        pName: "",
    }
};

layui.use(['layer', 'ztreeDistrict','form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var $ZTree = layui.ztreeDistrict;



    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/sysDistrict/detail?districtId=" + Feng.getUrlParam("districtId"));
    var result = ajax.start();
    form.val('sysDistrictForm', result.data);
    var jsonData = JSON.stringify(result);
    var json = $.parseJSON(jsonData);
    if(json.data.districtLevel == 1){
        document.getElementById('pName').disabled=true;
    }


    // 点击上级角色时
    $('#pName').click(function () {
        var formName = encodeURIComponent("parent.SysDistrictInfoDlg.data.pName");
        var formId = encodeURIComponent("parent.SysDistrictInfoDlg.data.parentId");
        var treeUrl = encodeURIComponent("/sysDistrict/tree");


        layer.open({
            type: 2,
            title: '父级部门',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/disCommonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#parentId").val(SysDistrictInfoDlg.data.parentId);
                $("#pName").val(SysDistrictInfoDlg.data.pName);
            }
        });
    });

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/sysDistrict/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            admin.putTempData('name', data);

            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});